home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / games2 / rotise12.zip / STENOG.C < prev    next >
C/C++ Source or Header  |  1992-04-03  |  9KB  |  352 lines

  1. /* Stenog.c
  2.  
  3.     Jonathan Arnold 1991
  4.  
  5.     Do all the secretarial and file functions, like:
  6.         comment - insert a comment
  7.         cost - describe the transaction costs
  8.         interval - read in the statistics data file to begin an interval
  9.         opsof - read in the old position file
  10.         slot - describe slots on the teams
  11.         bstats - list the statistics used for batters
  12.         pstats - list the statistics used for pitchers
  13.         salunit - how many pennies in a salary unit
  14. */
  15.  
  16. #include <stdio.h>
  17. #include <string.h>
  18.  
  19. #include "rotise.h"
  20.  
  21. #ifdef __TURBOC__
  22. #include <stdlib.h>
  23. #include <io.h>
  24. #include <alloc.h>
  25. #endif
  26.  
  27.  
  28. /* External data referenced */
  29. extern CMDLIST CmdTable[];                            /* cmdtable.c */
  30. extern int Cmd;                                            /* rotise.c */
  31. extern int InputLine;                                    /* Line # of current file */
  32. extern BOOL Verbose;                                    /* How talkative to be */
  33. extern char *InputFilename;                            /* Filename being read */
  34.  
  35. /* Local data publicly available */
  36. int Weeks = 0;                                    /* How many intervals read in */
  37. char IntvDate[MAX_DATE+1];                    /* Date string for current interval */
  38.  
  39.  /* salary units */
  40. int SalFree = 10;                                /* Free agent salary */
  41. int SalExp = 25;
  42.  
  43.  /* Costs */
  44. int CostRelease = 0;
  45. int CostClaim = 25;
  46. int CostReserve = 10;
  47. int CostExpand = 50;
  48. int CostWClaim = 10;                            /* Waiver claim */
  49. int CostActive = 10;                            /* Activate */
  50. int CostFarm = 10;                            /* Starting player in minors */
  51.  
  52.  
  53. /* Local routine prototypes */
  54. static opos_init PROTO( (PDB_PNAME *) );
  55.  
  56. /* Private data */
  57.     /* NONE */
  58.  
  59. /*
  60.     BOOL interval( int tokcnt, char *tokens[] )
  61.      Parse the line to get the statistices filename and the date for this
  62.     interval.  Optionally, the line could end with a filename of an updated
  63.     position list.
  64.  
  65.  ACCEPTS:
  66.     int tokcnt - how many tokens on this line
  67.     char *tokens[] - array pointing to each token
  68.  
  69.  RETURNS:
  70.     BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
  71. */
  72.  
  73. #define ARG_INV_DATE        1                    /* Date to use */
  74. #define ARG_INV_DFNM        2                    /* Data file name */
  75. #define ARG_INV_PFNM        3                    /* Position file name (optional) */
  76.  
  77. BOOL interval ARGLIST( (tokcnt, tokens) )
  78.     NFARG( int tokcnt )
  79.     FARG( char *tokens[] )
  80. {
  81.     int saveLine;
  82.     char saveName[20];
  83.     BOOL readstat;
  84.  
  85.     if ( tokcnt < ARG_INV_PFNM )
  86.         ARGCNT_ERR();
  87.  
  88.     if ( access( tokens[ARG_INV_DFNM], 0 ) != 0 )
  89.     { /* file doesn't exist */
  90.         rdb_error( "Interval - Unable to open file: ", tokens[ARG_INV_DFNM] );
  91.         return FALSE;
  92.     }
  93.  
  94.     VERBOSE( 1, "Week #%d: ", Weeks+1  );
  95.     VERBOSE( 1, "Parsing Stat file: %s.\n", tokens[ARG_INV_DFNM] );
  96.  
  97. #ifdef    __TURBOC__
  98.  
  99.     VERBOSE( 3, "Coreleft: %ld.\n", coreleft() );
  100.  
  101. #endif    __TURBOC__
  102.  
  103.     /* Save current input line and filename */
  104.     saveLine = InputLine;
  105.     strcpy( saveName, InputFilename );
  106.  
  107.     /* copy new file name for error reporting */
  108.     strcpy( InputFilename, tokens[ARG_INV_DFNM] );
  109.  
  110.     readstat = pdb_read( Weeks+1, tokens[ARG_INV_DFNM] );
  111.  
  112.     /* Restore error stuff */
  113.     InputLine = saveLine;
  114.     strcpy( InputFilename, saveName );
  115.  
  116.     if ( !readstat )
  117.     { /* oops, had a problem, give up on it */
  118.         rdb_error( "Interval - Problems parsing data in ", tokens[ARG_INV_DFNM] );
  119.         return FALSE;
  120.     }
  121.     
  122.     Weeks++;
  123.  
  124.     memset( IntvDate, 0, sizeof( IntvDate ) );
  125.  
  126.     if ( strlen( tokens[ARG_INV_DATE] ) > MAX_DATE )
  127.     { /* string too long, complain and truncate */
  128.         rdb_error( "Interval - Date string too long: ", tokens[ARG_INV_DATE] );
  129.         *(tokens[ARG_INV_DATE]+MAX_DATE) = '\0';
  130.     }
  131.  
  132.     strcpy( IntvDate, tokens[ARG_INV_DATE] );
  133.  
  134.     if ( tokcnt > ARG_INV_PFNM )
  135.     {    /* Read position info */
  136.         VERBOSE( 1, "Parsing Position File: %s.\n", tokens[ARG_INV_PFNM] );
  137.         pdb_readpos( tokens[ARG_INV_PFNM], 1 );
  138.     }
  139.  
  140.     return TRUE;
  141. }
  142.  
  143. /*
  144.     BOOL oposf( int tokcnt, char *tokens[] )
  145.      Read in and parse the position file from the previous year, adding as eligble
  146.     positions any played more than 19 games, or, if none, the one with the most games
  147.     played.
  148.  
  149.  ACCEPTS:
  150.     int tokcnt - how many tokens on this line
  151.     char *tokens[] - array pointing to each token
  152.  
  153.  RETURNS:
  154.     BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
  155. */
  156.  
  157. #define    ARG_OP_PFNM        1                    /* Name of position file */
  158. #define    ARG_OP_PMIN        2                    /* Min # of games required at pos. */
  159.  
  160. BOOL oposf ARGLIST( (tokcnt, tokens) )
  161.     NFARG( int tokcnt )
  162.     FARG( char *tokens[] )
  163. {
  164.     if ( tokcnt <= ARG_OP_PMIN )
  165.         ARGCNT_ERR();
  166.  
  167.     pdb_readpos( tokens[ARG_OP_PFNM], atoi( tokens[ARG_OP_PMIN] ) );
  168.  
  169.     /* now init all the players found in last year's file to zorch=-1 */
  170.     pdb_walk( opos_init );
  171.     return TRUE;
  172. }
  173.  
  174. static int opos_init ARGLIST( ( pnameP ) )
  175.      FARG( PDB_PNAME *pnameP )
  176. {
  177.     PDATA *pdataP;                            /* Player data */
  178.  
  179.     if ( pnameP == NULL )
  180.         return TRUE;
  181.  
  182.     pdataP = pdb_pdata( &pnameP->pn_lname[0], &pnameP->pn_fname[0],
  183.                                 pnameP->batter );
  184.  
  185.     pdataP->zorch = -1;
  186.  
  187.     return TRUE;
  188. }
  189.  
  190.  
  191. /*
  192.     BOOL slot( int tokcnt, char *tokens[] )
  193.      Add a slot description to the list of slots for this rotisserie league.
  194.     Also indicate which positions are valid for it.
  195.  
  196.  ACCEPTS:
  197.     int tokcnt - how many tokens on this line
  198.     char *tokens[] - array pointing to each token
  199.  
  200.  RETURNS:
  201.     BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
  202. */
  203.  
  204. #define    ARG_SLT_SLOT    1                    /* Slot name */
  205. #define    ARG_SLT_POS        2                    /* First of any valid positions */
  206.  
  207. BOOL slot ARGLIST( (tokcnt, tokens) )
  208.     NFARG( int tokcnt )
  209.     FARG( char *tokens[] )
  210. {
  211.     int        i;
  212.     UWORD        posmask;
  213.     RDB_SLOT    slotinf;                            /* Slot info */
  214.  
  215.     /* Make sure there are plenty of tokens */
  216.     if ( tokcnt < ARG_SLT_POS )
  217.         ARGCNT_ERR();
  218.  
  219.     if ( Verbose >= 4 )
  220.     { /* Print some ugly stuff. */
  221.        fprintf( stderr, "Define slot %s; position list: %s",
  222.                      tokens[ARG_SLT_SLOT], tokens[ARG_SLT_POS] );
  223.         for ( i = ARG_SLT_POS +1; i < tokcnt; ++i )
  224.             fprintf( stderr, ", %s", tokens[i] );
  225.         fprintf( stderr, "\n" );
  226.     }
  227.  
  228.     /* Build slot info */
  229.     strncpy( slotinf.slot, tokens[ARG_SLT_SLOT], MAX_SLOT );
  230.     slotinf.slot[MAX_SLOT] = NUL;
  231.     slotinf.pos = 0;
  232.  
  233.     for( i = ARG_SLT_POS; i < tokcnt; ++i ) {
  234.         posmask = pos_to_mask( tokens[i] );
  235.         if ( posmask == 0 )
  236.         {    /* Not a good position. */
  237.             rdb_error( "Unknown position: ", tokens[i] );
  238.         }
  239.         else
  240.             slotinf.pos |= posmask;
  241.     }
  242.  
  243.     if ( slotinf.pos == 0 )
  244.     {    /* No valid positions found. */
  245.         rdb_error( "Slot has no valid positions: ", slotinf.slot );
  246.     }
  247.     else
  248.     {    /* Go ahead and define it. */
  249.         slot_add( &slotinf );
  250.     }
  251.  
  252.     return TRUE;
  253. }
  254.  
  255. /*
  256.     BOOL bstats ( int tokcnt, char *tokens[] )
  257.      Tell which statistics will be used for batters.  The defaults are BA, RBI,
  258.     HR, and SB.
  259.  
  260.  ACCEPTS:
  261.     int tokcnt - how many tokens on this line
  262.     char *tokens[] - array pointing to each token
  263.  
  264.  RETURNS:
  265.     BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
  266. */
  267.  
  268. BOOL  bstats ARGLIST( (tokcnt, tokens) )
  269.     NFARG( int tokcnt )
  270.     FARG( char *tokens[] )
  271. {
  272.     return TRUE;
  273. }
  274. /*
  275.     BOOL pstats( int tokcnt, char *tokens[] )
  276.      Tell which statistics will be used for pitchers.  The defaults are W, Saves,
  277.     ERA, and Ratio ((H+BB)/IP)
  278.  
  279.  ACCEPTS:
  280.     int tokcnt - how many tokens on this line
  281.     char *tokens[] - array pointing to each token
  282.  
  283.  RETURNS:
  284.     BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
  285. */
  286.  
  287. BOOL pstats ARGLIST( (tokcnt, tokens) )
  288.     NFARG( int tokcnt )
  289.     FARG( char *tokens[] )
  290. {
  291.     return TRUE;
  292. }
  293.  
  294. /*
  295.     BOOL cost( int tokcnt, char *tokens[] )
  296.      Describe the transactions costs for this league.
  297.  
  298.  ACCEPTS:
  299.     int tokcnt - how many tokens on this line
  300.     char *tokens[] - array pointing to each token
  301.  
  302.  RETURNS:
  303.     BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
  304. */
  305.  
  306. BOOL cost ARGLIST( (tokcnt, tokens) )
  307.     NFARG( int tokcnt )
  308.     FARG( char *tokens[] )
  309. {
  310.     return TRUE;
  311. }
  312.  
  313. /*
  314.     BOOL salunit( int tokcnt, char *tokens[] )
  315.      How many pennies in a salary unit.  Salaries and costs are all specified in
  316.     "salary units", so this is used to format the output.
  317.  
  318.  ACCEPTS:
  319.     int tokcnt - how many tokens on this line
  320.     char *tokens[] - array pointing to each token
  321.  
  322.  RETURNS:
  323.     BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
  324. */
  325.  
  326. BOOL salunit ARGLIST( (tokcnt, tokens) )
  327.     NFARG( int tokcnt )
  328.     FARG( char *tokens[] )
  329. {
  330.     return TRUE;
  331. }
  332.  
  333. /*
  334.     BOOL comment( int tokcnt, char *tokens[] )
  335.      Just ignore the rest of the line.
  336.  
  337.  ACCEPTS:
  338.     int tokcnt - how many tokens on this line
  339.     char *tokens[] - array pointing to each token
  340.  
  341.  RETURNS:
  342.     BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
  343. */
  344.  
  345. BOOL comment ARGLIST( (tokcnt, tokens) )
  346.     NFARG( int tokcnt )
  347.     FARG( char *tokens[] )
  348. {
  349.     return TRUE;
  350. }
  351.  
  352.